2020-2021 Sunseeker Telemetry and Lighting System
usci_b_i2c_ex3_slaveRxSingle.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //*****************************************************************************
51 //
52 //*****************************************************************************
53 //*****************************************************************************
54 //
55 //Set the address for slave module. This is a 7-bit address sent in the
56 //following format:
57 //[A6:A5:A4:A3:A2:A1:A0:RS]
58 //
59 //A zero in the "RS" position of the first byte means that the master
60 //transmits (sends) data to the selected slave, and a one in this position
61 //means that the master receives data from the slave.
62 //
63 //*****************************************************************************
64 #define SLAVE_ADDRESS 0x48
65 
66 uint8_t receivedData;
67 
68 void main (void)
69 {
70  //Stop WDT
71  WDT_A_hold(WDT_A_BASE);
72 
73  //Assign I2C pins to USCI_B0
74  GPIO_setAsPeripheralModuleFunctionInputPin(
75  GPIO_PORT_P3,
76  GPIO_PIN1 + GPIO_PIN2
77  );
78 
79  //Initialize I2C as a slave device with slave address as SLAVE_ADDRESS
80  USCI_B_I2C_initSlave(USCI_B0_BASE,
82  );
83 
84  //Set in receive mode
85  USCI_B_I2C_setMode(USCI_B0_BASE,
86  USCI_B_I2C_RECEIVE_MODE
87  );
88 
89  //Enable I2C Module to start operations
90  USCI_B_I2C_enable(USCI_B0_BASE);
91 
92  //Enable receive interrupt
93  USCI_B_I2C_clearInterrupt(USCI_B0_BASE,
94  USCI_B_I2C_RECEIVE_INTERRUPT
95  );
96  USCI_B_I2C_enableInterrupt(USCI_B0_BASE,
97  USCI_B_I2C_RECEIVE_INTERRUPT
98  );
99 
100  //Enter LPM0, enable interrupts
101  __bis_SR_register(LPM0_bits + GIE);
102 
103  //Set breakpoint >>here<< and read received data
104  __no_operation();
105 }
106 
107 //******************************************************************************
108 //
109 //This is the USCI_B0 interrupt vector service routine.
110 //
111 //******************************************************************************
112 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
113 #pragma vector=USCI_B0_VECTOR
114 __interrupt
115 #elif defined(__GNUC__)
116 __attribute__((interrupt(USCI_B0_VECTOR)))
117 #endif
118 void USCI_B0_ISR (void)
119 {
120  switch (__even_in_range(UCB0IV,12)){
121  //Vector 10: Data received - RXIFG
122  case USCI_I2C_UCRXIFG:
123  {
124  //Get received data
125  receivedData = USCI_B_I2C_slaveGetData(USCI_B0_BASE);
126  break;
127  }
128  default:
129  break;
130  }
131 }
132 
__no_operation()
uint8_t receivedData
void main(void)
void USCI_B0_ISR(void)
#define SLAVE_ADDRESS